@layout("/common/_container1.html"){
<div class="ibox float-e-margins">
    <div class="ibox-content">
        <div class="form-horizontal" id="announcementInfoForm">

            <div class="row">
                <input id="id" type="hidden" value="${item.id}">
                <input type="hidden" id="contentVal" value='${item.content}'>
                <input type="hidden" id="uploadUrl" value="${uploadUrl}">
                <div class="col-sm-12 b-r">
                    <#select id="tzggType" name="公告类型" underline="true">
                    @for(type in types){
                    <option value="${type.id}" ${item.tzggType==type.id?'selected':""}>${type.name}</option>
                    @}
                </#select>
                <#input id="userName" name="作者" underline="true" value="${item.userName}"/>
                <div class="form-group">
                    <label class="col-sm-3 control-label">标题<span style="color: red; ">*</span></label>
                    <div class="col-sm-9">
                        <textarea id="title" name="title" rows="3" style="width: 100%">${item.title}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">内容摘要<span style="color: red; ">*</span></label>
                    <div class="col-sm-9">
                        <textarea id="brief" name="brief" rows="3" style="width: 100%">${item.brief}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">是否首页显示</label>
                    <div class="col-sm-9">
                        <input type="radio"  name="isDisplay" value="0" ${item.isDisplay==null?'checked':""}/>不显示
                        <input type="radio" name="isDisplay" value="1" checked ${item.isDisplay!=null?'checked':""}/>显示
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">内容<span style="color: red; ">*</span></label>
                    <div class="col-sm-9">
                        <div id="editor"   class="editorHeight">
                    </div>
                </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">附件上传</label>
                    <input type="hidden" name="attachs" id="attachs" value="${item.attachs}"/>
                    <div class="col-sm-9">
                        <input id="input-ke-2" name="file" multiple="multiple" type="file" data-show-caption="true">
                    </div>
                </div>

            </div>
        </div>

        <div class="row btn-group-m-t">
            <div class="col-sm-10" style="text-align: center">
                <#button btnCss="info" name="发布" id="ensure" icon="fa-paper-plane" clickFun="PtAnnouncementInfoDlg.editSubmit()"/>
                <#button btnCss="danger" name="存草稿" id="cancel" icon="fa-clipboard" clickFun="PtAnnouncementInfoDlg.draftSubmit()"/>
            </div>
        </div>
    </div>

</div>
</div>
<link href="${ctxPath}/static/plugins/bootstrap-fileinput/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
<link href="${ctxPath}/static/plugins/bootstrap-fileinput/themes/explorer-fa/theme.css" media="all" rel="stylesheet" type="text/css"/>
<script src="${ctxPath}/static/modular/system/xymh/ptAnnouncement/ptAnnouncement_info.js"></script>
<script src="${ctxPath}/static/plugins/bootstrap-fileinput/js/plugins/sortable.js" type="text/javascript"></script>
<script src="${ctxPath}/static/plugins/bootstrap-fileinput/js/fileinput.js" type="text/javascript"></script>
<script src="${ctxPath}/static/plugins/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
<script src="${ctxPath}/static/plugins/bootstrap-fileinput/themes/explorer-fa/theme.js" type="text/javascript"></script>
<script src="${ctxPath}/static/plugins/bootstrap-fileinput/themes/fa/theme.js"></script>
<script src="${ctxPath}/static/plugins/bootstrap-fileinput/themes/fa/theme.js"></script>
<script type="text/javascript" src="${ctxPath}/static/js/plugins/wangEditor/wangEditor.js"></script>
<script>
    var ids = $("#attachs").val();
    $(document).ready(function() {
        if ('${rList}'!=null){
        var rList=eval('${rList}');
        var preHtml=[];
        var preConfig=[];
            var   List=[];
        if (rList.length>0){
            for ( var i in rList) {
                preHtml[i]= " <div class='file-preview-text'>" +
                    "<h2><i class='glyphicon glyphicon-file' ></i></h2>" + rList[i].name+'.'+rList[i].ext + "</div>";
              var obj={"caption": rList[i].name+'.'+rList[i].ext,"type":rList[i].ext,"key":rList[i].id};
             preConfig.push(obj)
            }

        }
        }
        $("#input-ke-2").fileinput({
            language:'zh',
            dropZoneTitle: '可以将图片拖放到这里 …支持多文件上传',
            theme: "explorer-fa",                               // 主题
            uploadUrl: $("#uploadUrl").val(),         // 上传地址
            minFileCount: 1,                                        // 最小上传数量
            maxFileCount: 5,                                        // 最大上传数量
            overwriteInitial: false,                        // 覆盖初始预览内容和标题设置
            showCancel:true,                                       // 显示取消按钮
            showZoom:false,                                         // 显示预览按钮
            showCaption:false,                                  // 显示文件文本框
            dropZoneEnabled:false,                          // 是否可拖拽
            uploadLabel:"上传附件",                         // 上传按钮内容
            browseLabel: '选择附件',                            // 浏览按钮内容
            showRemove:false,                                       // 显示移除按钮
            browseClass:"btn btn-primary",                        // 浏览按钮样式
            uploadClass:"btn btn-primary",
            enctype: 'multipart/form-data',// 上传按钮样式
            preferIconicPreview: true,
            initialPreviewAsData:true,
            previewFileIconSettings: { // configure your icon file extensions
                'doc': '<i class="fa fa-file-word-o text-primary"></i>',
                'xls': '<i class="fa fa-file-excel-o text-success"></i>',
                'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
                'txt': '<i class="fa fa-file-text-o text-info"></i>',
                'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
                'htm': '<i class="fa fa-file-code-o text-info"></i>',
                'mov': '<i class="fa fa-file-movie-o text-warning"></i>',
                'mp3': '<i class="fa fa-file-audio-o text-warning"></i>'
            },
            initialPreview: preHtml,
            initialPreviewConfig:preConfig,
            uploadExtraData: function(previewId, index) {   //该插件可以向您的服务器方法发送附加数据。这可以通过uploadExtraData在键值对中设置为关联数组对象来完成。所以如果你有设置uploadExtraData={id:'kv-1'}，在PHP中你可以读取这些数据$_POST['id']
                var id = $('#id').val();
                return {seriesId: id};
            },
            allowedFileExtensions: ['doc','docx','xls','xlsx','ppt','pptx','pdf','txt','zip','rar'],//接收的文件后缀
            hideThumbnailContent:false,// 是否隐藏文件内容
            showUpload: true,
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
            fileActionSettings: {                               // 在预览窗口中为新选择的文件缩略图设置文件操作的对象配置
                showRemove: false,                                   // 显示删除按钮
                showUpload: true,                                   // 显示上传按钮
                showDownload: false,                            // 显示下载按钮
                showZoom: false,                                    // 显示预览按钮
                showDrag: false,                                        // 显示拖拽
                removeIcon: '<i class="fa fa-trash"></i>',   // 删除图标
                uploadIcon: '<i class="fa fa-upload"></i>',     // 上传图标
                uploadRetryIcon: '<i class="fa fa-repeat"></i>'  // 重试图标
            },
            layoutTemplates:{
                actionDelete:'',

            }
        }).on("fileuploaded", function(event, data,previewId,index) {    //此处是上传成功回调函数
            if (data.response) {
                $.ajax({
                    type:"post",
                    async : false,
                    url:Feng.ctxPath+"/file/saveResource",
                    data:{'name':data.files[index].name,'rmsResId':data.response.key,'size':data.files[index].size,'path':"photo/ico","ext":getFileType(data.files[index].name)},
                    dataType:"json",
                    cache: false,
                    success: function(obj){
                        if(obj){
                            if(ids){
                                ids+="#";
                            }
                            ids += data.response.key;
                            $("#attachs").val(ids);
                            List.push({KeyID: previewId,fileId: data.response.key})
                        }
                    },
                });
            }
        });
        $("#input-ke-2").fileinput('_initFileActions');
        $('#input-ke-2').on('filedeleted', function(event, key) {
            console.log('Key = ' + key);
        });
        $('#input-ke-2').on('filesuccessremove', function(event, data) {
            for (var i = 0; i < List.length; i++) {
                if (List[i].KeyID ===data) {
                    fileId=List[i].fileId;

                    strs=$("#attachs").val().split("#");
                    if (strs.length==1){
                        $("#attachs").val("");
                    } else {
                        for(i =strs.length; i>0; i--) {
                            if (strs[i]===fileId){
                                strs.splice(i,1)
                            }
                        }
                        if (strs.length>0){
                            $("#attachs").val(strs.join("#"));
                        }else {
                            $("#attachs").val();
                        }
                    }
                    List[i].FileUrl='';
                    List[i].KeyID='';
                }
            }
        });
        $('#input-ke-2').on('fileremoved', function(event, data,key) {
           layer.alert("修改时不允许删除附件")
            });
        // 上传成功回调
        $("#input-ke-2").on("filebatchuploadcomplete", function(event, data) {
            Feng.success("上传附件成功");
            // setTimeout("closeUpladLayer()",2000)
        });
        // 上传失败回调
        $('#input-ke-2').on('fileerror', function(event, data, msg) {
            layer.msg(data.msg);
            //tokenTimeOut(data);
        });
    });
    function getFileType(filePath){
        var startIndex = filePath.lastIndexOf(".");
        if(startIndex != -1)
            return filePath.substring(startIndex+1, filePath.length).toLowerCase();
        else return "";
    };
</script>
@}
